package org.jeecg.controller;

import org.jeecg.domain.Goods;
import org.jeecg.result.ResultTool;
import org.jeecg.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @RequestMapping(value = "/getAll",method = RequestMethod.GET)
    public ResultTool getAll(){
        List<Goods> allGoods = goodsService.getAllGoods();
        return new ResultTool(allGoods,200);
    }

    @RequestMapping(value = "addGoods",method = RequestMethod.POST)
    public ResultTool addGoods(@RequestBody Goods goods){
        Boolean add = goodsService.add(goods);
        if (add){
            return new ResultTool(200,"发布成功");
        }
        return new ResultTool(400,"发布失败");
    }
}
